package com.ruoyi.medical.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.medical.mapper.ChecksMapper;
import com.ruoyi.medical.domain.Checks;
import com.ruoyi.medical.service.IChecksService;

import javax.annotation.Resource;

/**
 * 检查结果Service业务层处理
 *
 * @author ruoyi
 * @date 2024-02-28
 */
@Service
public class ChecksServiceImpl implements IChecksService
{
    @Resource
    private ChecksMapper checksMapper;

    /**
     * 查询检查结果
     *
     * @param id 检查结果主键
     * @return 检查结果
     */
    @Override
    public Checks selectChecksById(Long id)
    {
        return checksMapper.selectChecksById(id);
    }

    /**
     * 查询检查结果列表
     *
     * @param checks 检查结果
     * @return 检查结果
     */
    @Override
    public List<Checks> selectChecksList(Checks checks)
    {
        return checksMapper.selectChecksList(checks);
    }

    /**
     * 新增检查结果
     *
     * @param checks 检查结果
     * @return 结果
     */
    @Override
    public int insertChecks(Checks checks)
    {
        checks.setCreateTime(DateUtils.getNowDate());
        //CreateBy
        String username = SecurityUtils.getUsername();
        if (StringUtils.isEmpty(username)){
            throw new RuntimeException("用户名不存在");
        }else {
            checks.setCreateBy(username);
        }
        return checksMapper.insertChecks(checks);
    }

    /**
     * 修改检查结果
     *
     * @param checks 检查结果
     * @return 结果
     */
    @Override
    public int updateChecks(Checks checks)
    {
        checks.setUpdateTime(DateUtils.getNowDate());
        //UpdateBy
        String username = SecurityUtils.getUsername();
        if (StringUtils.isEmpty(username)){
            throw new RuntimeException("用户名不存在");
        }else {
            checks.setUpdateBy(username);
        }
        return checksMapper.updateChecks(checks);
    }

    /**
     * 批量删除检查结果
     *
     * @param ids 需要删除的检查结果主键
     * @return 结果
     */
    @Override
    public int deleteChecksByIds(Long[] ids)
    {
        return checksMapper.deleteChecksByIds(ids);
    }

    /**
     * 删除检查结果信息
     *
     * @param id 检查结果主键
     * @return 结果
     */
    @Override
    public int deleteChecksById(Long id)
    {
        return checksMapper.deleteChecksById(id);
    }
}
